package com.ydx.demo.mapper;

import com.ydx.demo.entity.Medicine;
import com.ydx.demo.entity.Shopcart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface MedicineMapper {
    //查询所有
    @Select("select * from medicine")
    List<Medicine> finAll();

    //根据药品编号模糊查询
    @Select("""
            SELECT *
            FROM medicine
            WHERE code LIKE CONCAT('%', #{code}, '%')
            """)
    List<Medicine> seleceMedicine(Medicine medicine);

    //添加接口
    @Insert("""
            insert into medicine(id,drugname,price,drugdetail)
            values(#{id},#{drugname},#{price},#{drugdetail})
            """)
    @Transactional
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Medicine medicine);

    //删除药品表
    @Delete("delete from medicine where id = #{id}")
    int DelMedicine(Medicine medicine);

    //修改药品表
    @Update("update medicine set drugname=#{drugname},price=#{price},drugdetail=#{drugdetail} where id=#{id}")
    void UpdateMedicine(Medicine medicine);

    //修改药品表的图片路径
    @Update("update medicine set images = #{images} where id = #{id}")
    void UpdateImages(Medicine medicine);

    //----------
    //查询购物车表
    @Select("select * from shopcart")
    List<Shopcart> selectShopAll();

    // 新增购物车数据
    @Insert("""
            INSERT INTO shopcart (drugld, quantity)
            VALUES (#{drugld}, #{quantity})
            """)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertShoppingtrolley(Shopcart shopcart);

    //左连接多表联查
    @Select("""
            select shopcart.id,medicine.drugname,medicine.price,shopcart.quantity,shopcart.drugld 
            from medicine 
            left join shopcart on medicine.id=shopcart.drugld
    """)
    List<Shopcart> selectShop();

    //删除购物车数据
    @Delete("delete from shopcart where id = #{id}")
    int DelShopping(Shopcart shopcart);
//    //user添加
//    @Insert("""
//            insert into user(email,phone,name,password,sex)
//            values(#{email},#{phone},#{name},#{password},#{sex})
//            """)
//    @Options(useGeneratedKeys = true, keyProperty = "id")
//    void userAdd(User user);
//
//    // 查询对应用户信息
//    @Select("SELECT * FROM user WHERE email = #{email} AND password = #{password}")
//    List<User> LoginCheck(User user);
//
//    //查询用户信息
//    @Select("SELECT * FROM user")
//    List<User> userData(User user);
//
//    //修改用户信息
//    @Update("update user set phone=#{phone},name=#{name},password=#{password},sex=#{sex} where email=#{email}")
//    void  updateUser(User user);
//
//    //删除用户信息
//    @Delete("delete from user where id=#{id}")
//    void delUser(User user);
}
